package swing;

import beans.Whiteboard;
import swing.frame.LoginFrame;
import swing.frame.MainFrame;
import swing.frame.whiteboard.MyDrawPanel;

import javax.swing.*;

/**
 * 全局窗口管理器
 * 每个窗口保持唯一实例，避免重复创建
 */
public class FrameManager {

    public static LoginFrame loginFrame;
    public static MainFrame mainFrame;

    public static BaseFrame curFrame;
    //public static BaseFrame drawFrame;
    /**
     * 显示登录界面
     */
    public static void showLoginFrame() {
        if (loginFrame == null || !loginFrame.isEnabled()) {
            loginFrame = new LoginFrame();
        }
        loginFrame.showFrame();
        curFrame = loginFrame;
    }

    /**
     * 显示程序主界面
     */
    public static void showMainFrame() {
        if (mainFrame == null || !mainFrame.isEnabled()){
            mainFrame = new MainFrame();
        }
        mainFrame.showFrame();
        curFrame = mainFrame;
    }

    public static void showWhiteBoard(Whiteboard whiteboard, boolean isAdmin,String groupName){
        MyDrawPanel myDrawPanel=new MyDrawPanel(whiteboard, isAdmin,groupName);
    }

    public static void showMessageDialog(String message){
        JOptionPane.showMessageDialog(curFrame, message);
    }

}
